package com.xiaoshuidi.cloud.module.system.api.receipt;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.module.system.api.receipt.dto.ReceiptDataRespDTO;
import com.xiaoshuidi.cloud.module.system.controller.admin.receipt.vo.ReceiptRespVO;
import com.xiaoshuidi.cloud.module.system.service.receipt.ReceiptService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

import static com.xiaoshuidi.cloud.module.system.enums.ApiConstants.VERSION;

@RestController // 提供 RESTful API 接口，给 Feign 调用
@DubboService(version = VERSION) // 提供 Dubbo RPC 接口，给 Dubbo Consumer 调用
@Validated
public class ReceiptConfigApiImpl implements ReceiptConfigApi {
    @Resource
    private ReceiptService receiptService;
    @Override
    public CommonResult<ReceiptDataRespDTO> getReceiptConfig(Long apartmentId) {
        ReceiptRespVO receiptRespVO = receiptService.get(apartmentId);
        ReceiptDataRespDTO receiptDataRespDTO = null;
        if (receiptRespVO != null){
            receiptDataRespDTO = new ReceiptDataRespDTO();
            BeanUtils.copyProperties(receiptRespVO,receiptDataRespDTO);
        }
        return CommonResult.success(receiptDataRespDTO);
    }
}
